package com.ys.service.Impl;

import com.ys.mapper.WarehouseMapper;
import com.ys.pojo.Bittable;
import com.ys.pojo.Warehouse;
import com.ys.service.BittableService;
import com.ys.service.WarehouseService;
import com.ys.vo.TreeVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service("warehouseService")
public class WarehouseServiceImpl implements WarehouseService {
    @Resource
    private WarehouseMapper warehouseMapper;

    @Override
    public List<Warehouse> selectWarehouse(String name1, String name2, String name3) {
        return warehouseMapper.selectWarehouse(name1,name2,name3);
    }

    @Override
    public boolean addsinsertWarehouse(Warehouse warehouse) {
        return warehouseMapper.addsinsertWarehouse(warehouse);
    }

    @Override
    public boolean updsupdateWarehouse(Warehouse warehouse) {
        return warehouseMapper.updsupdateWarehouse(warehouse);
    }

    @Override
    public boolean deltes(Integer[] ids) {
        return warehouseMapper.deltes(ids);
    }

    @Resource
    private BittableService bittableService;


    @Override
    public List<Warehouse> searchStatic() {
        return warehouseMapper.findStatic();
    }

    @Override
    public List<TreeVo> searchAll() {
        List<Warehouse> list = warehouseMapper.findStatic();
        List<TreeVo> treeVoList = new ArrayList<>();
        for (Warehouse item:list){
            List<Bittable> bitlist = bittableService.searchAll(item.getWid());
            List<TreeVo> treeVoList1 = new ArrayList<>();
            for (Bittable bit:bitlist){

                //块
                List<TreeVo> treeVoList4 = new ArrayList<>();
                TreeVo treeVo5 = new TreeVo(bit.getBitId(),bit.getBitfrmLayerBlock(),false,new ArrayList<>());
                treeVoList4.add(treeVo5);

                //层
                List<TreeVo> treeVoList3 = new ArrayList<>();
                TreeVo treeVo4 = new TreeVo(bit.getBitId(),bit.getBitframeLayer(),false,treeVoList4);
                treeVoList3.add(treeVo4);


                //架
                List<TreeVo> treeVoList2 = new ArrayList<>();
                TreeVo treeVo3 = new TreeVo(bit.getBitId(),bit.getBitframe(),false,treeVoList3);
                treeVoList2.add(treeVo3);

                //区
                TreeVo treeVo2 = new TreeVo(bit.getBitId(),bit.getBitDist(),false,treeVoList2);
                treeVoList1.add(treeVo2);
            }

            //仓库
            TreeVo treeVo1 = new TreeVo(item.getWid(),item.getWname(),false,treeVoList1);
            treeVoList.add(treeVo1);
        }
        return treeVoList;
    }
}
